package week02;
import static java.lang.System.out;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class TrafficJobClient {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf,"TrafficCounting");

        job.setJarByClass(TrafficJobClient.class);

        job.setMapperClass(TrafficMapper.class);

        job.setReducerClass(TrafficReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(TrafficRecord.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(TrafficRecord.class);

        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        boolean b = job.waitForCompletion(true);

        if (!b){
            out.println("TrafficCounting task failed.");
        }

    }
}
